package com.fhz.main.ui.home

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.fhz.common.entity.MeiNv
import com.fhz.main.databinding.HomeRvLayoutBinding

/**
 * 时间:2023/4/12
 * @author Mr.Feng
 * 简述: 首页rv适配器
 */
class HomeRVAdapter(var con:Context?,var meiNvList:List<MeiNv>) : BaseQuickAdapter<MeiNv, HomeRVAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: HomeRvLayoutBinding = HomeRvLayoutBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: MeiNv?) {
        // 设置item数据
        val meiNv = meiNvList[position]
//        holder.binding.rvTvName.text = meiNv.title
        //也可以直接用binding
        holder.binding.rvImMeinv.adjustViewBounds = true
        val layoutParams: ViewGroup.LayoutParams = holder.binding.rvImMeinv.getLayoutParams()
        con?.let { Glide.with(it).load(meiNv.url).override(layoutParams.width, Integer.MAX_VALUE).into(holder.binding.rvImMeinv) }

        holder.binding.meinv = meiNv

    }

}